<?php

/**
 * Adminhtml grid item renderer
 *
 * @category   VES
 * @package    VES_Vendors
 * @author     Vnecoms Team <support@vnecoms.com>
 */

class EM_Multidealpro_Block_Adminhtml_Renderer_TotalQuantity
    extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
{
	/**
     * Renders grid column
     *
     * @param   Varien_Object $row
     * @return  string
     */
    
/* you 显示产品数量，组合产品总数量 2016-07-22 */
    public function render(Varien_Object $row)
    {
        $productId  = $row->getData('entity_id');
        $__invAmt   = $this->isTotalInventory($productId);
        $__invAmts  = array();
        $childrenIds   =Mage::getModel('catalog/product_type_configurable')->getChildrenIds($productId);
        foreach($childrenIds as $Ids){
            foreach($Ids as $productId){
                $__invAmtst = $this->isTotalInventory($productId);
                $__invAmts[]=$__invAmtst;
            }
        }
        for($i=0;$i<count($__invAmts);$i++){
            $__invAmt = $__invAmt + $__invAmts[$i];
        }
        return '<div>'.$__invAmt.'</div>';
    }

    /*获取产品库存*/

    protected function isTotalInventory($productId)
    {
        $_product = Mage::getModel('catalog/product')->load($productId);
        $__invAmt = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
        return $__invAmt;
    }
}
